package com.newsmanagement.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author xbr
 * controller返回数据统一格式
 */
public class ReturnedMessages {

    // 返回提示信息
    private String message;

    // 返回的状态码
    // 成功：200  ；失败（执行sql语句无结果或错误）：400 ；程序异常：500
    private Integer code;

    // 返回的数据
    private Object data;

    public ReturnedMessages() {
        this.message = "success!";
        this.code = 200;
    }

    public ReturnedMessages(String message, Integer code, Object data) {
        this.message = message;
        this.code = code;
        this.data = data;
    }

    public ReturnedMessages(String message, Integer code) {
        this.message = message;
        this.code = code;
    }

    /**
     * 错误时赋值
     * @param code
     * @param message
     * @return
     */
    public ReturnedMessages ReturnedMessagesFail(Integer code, String message) {
        return new ReturnedMessages(message ,code);
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
